

library(foreign)
library(scatterplot3d)
setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
trad<-read.dta("pop9010TRAD.dta") #Stata file with demographic data#
attach(trad)
pdf("figureS2_Rcode.pdf", width=7, height=7)
par(mfrow=c(3,3), oma=c(0,0,2,0))


#HISPANIC POPULATION BY HISPANIC CHANGE

#x=Hispanic State Population Consisting 
#y-Percentage Change in Hisp Pop, 1990 to 2010 
 
 statehisp2010=100*(hispanic10/total10)
 
plot(statehisp2010, roc_hispanic, pch=21, xlab="Percent Hispanic, 2010", ylab="% Change, 1990-2010", main="A. State Hispanic Population", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,50), col="gray", bg="gray")
legend("topright", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), bg=c("black", "gray", "gray"), col=c("black", "gray", "grey"),   bty="n", cex=.65)
text(40, 350, "r=-.27 (.05)", col="black", cex=.65)



detach(trad)
remove(list=ls())


nd<-read.dta("pop9010NEWDEST.dta") #Stata file with demographic data#
attach(nd)

par(new="TRUE")

statehisp2010=100*(hispanic10/total10)
 
plot(statehisp2010, roc_hispanic, pch=21, xlab="", ylab="", main="", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,50), col="black", bg="black")

detach(nd)
remove(list=ls())



rs<-read.dta("pop9010REMAINING.dta") #Stata file with demographic data#
attach(rs)


#Creates Plots of Population Characteristics: Figure 1

par(new="TRUE")

statehisp2010=100*(hispanic10/total10)
 
plot(statehisp2010, roc_hispanic, pch=1, xlab="", ylab="", main="", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,50), col="black", bg="white")



detach(rs)
remove(list=ls())


############################################
#Foreign Born Population####################


trad<-read.dta("pop9010TRAD.dta") #Stata file with demographic data#
attach(trad)

#Plot 1: 
#x=Foreign Born State Population Consisting 
#y-Percentage Change in Hisp Pop, 1990 to 2010 
 
 forborn2010<-forborn10/total10*100

 
plot(forborn2010, roc_forborn, pch=21, xlab="Percent Foreign Born, 2010", ylab="% Change, 1990-2010", main="B. State For.-Born Population", cex.main=.85,  
cex.lab=.85, cex.axis=.85, ylim=c(0,600), xlim=c(0,30), col="gray", bg="gray")
legend("topright", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), bg=c("black", "gray", "gray"), col=c("black", "gray", "grey"),   bty="n", cex=.65)
text(25, 300, "r=-.16 (.26)", col="black", cex=.65)





detach(trad)
remove(list=ls())


nd<-read.dta("pop9010NEWDEST.dta") #Stata file with demographic data#
attach(nd)


#Creates Plots of Population Characteristics: Figure 1

par(new="TRUE")

forborn2010<-forborn10/total10*100

plot(forborn2010, roc_forborn, pch=21, xlab="", ylab="", main="", cex.main=.85,  
cex.lab=.85, cex.axis=.85, ylim=c(0,600), xlim=c(0,30), col="black", bg="black")

detach(nd)
remove(list=ls())


rs<-read.dta("pop9010REMAINING.dta") #Stata file with demographic data#
attach(rs)


par(new="TRUE")


 forborn2010<-forborn10/total10*100

 
plot(forborn2010, roc_forborn, pch=1, xlab="", ylab="", main="", cex.main=.85,  
cex.lab=.85, cex.axis=.85, ylim=c(0,600), xlim=c(0,30), col="black", bg="white")

detach(rs)
remove(list=ls())


###########################
HISPANIC CHANGE BY FOREIGN BORN
############################


trad<-read.dta("pop9010TRAD.dta") #Stata file with demographic data#
attach(trad)


#HISPANIC POPULATION x FOR BORN

#Plot 1: 
#x=Hispanic State Population Consisting 
#y-Percentage Change in Hisp Pop, 1990 to 2010 
 
plot(roc_forborn, roc_hispanic, pch=21, xlab="Percent Change For. Born, 1990-2010", ylab="% Change Hispanic, 1990-2010", main="C. Hispanic Population by For. Born", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,600), col="gray", bg="gray")
legend("topleft", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), bg=c("black", "gray", "gray"), col=c("black", "gray", "grey"),   bty="n", cex=.65)
text(400, 200, "r=.89 (.00)", col="black", cex=.65)






detach(trad)
remove(list=ls())


nd<-read.dta("pop9010NEWDEST.dta") #Stata file with demographic data#
attach(nd)

par(new="TRUE")

 
plot(roc_forborn, roc_hispanic, pch=21, xlab="", ylab="", main="", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,600), col="black", bg="black")

detach(nd)
remove(list=ls())



rs<-read.dta("pop9010REMAINING.dta") #Stata file with demographic data#
attach(rs)


#Creates Plots of Population Characteristics: Figure 1

par(new="TRUE")

 
plot(roc_forborn, roc_hispanic, pch=1, xlab="", ylab="", main="", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,600), col="black", bg="white")


detach(rs)
remove(list=ls())




############################################
#Unauthorized Population

trad<-read.dta("pop9010TRAD.dta") #Stata file with demographic data#
attach(trad)


#x=Percentage of State Population Consisting of Undocumented
#y-Percentage Change in Unauth Pop, 1990 to 2010 
  
uachange9010<-100*((unauth2010-unauth90)/unauth90)
ua2010state<-100*(unauth2010*1000/total10)


 
plot(ua2010state, uachange9010, pch=21, xlab="Percent Unauthorized: 2010", ylab="% Change, 1990-2010", main="D. Unauthorized Population", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,2300), xlim=c(0,7), col="gray", bg="gray")
legend("topleft", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), bg=c("black", "gray", "gray"), col=c("black", "gray", "grey"),   bty="n", cex=.65)
text(5, 1500, "r=-.03 (.23)", col="black", cex=.65)





detach(trad)
remove(list=ls())


nd<-read.dta("pop9010NEWDEST.dta") #Stata file with demographic data#
attach(nd)


#Creates Plots of Population Characteristics: Figure 1

par(new="TRUE")

uachange9010<-100*((unauth2010-unauth90)/unauth90)
ua2010state<-100*(unauth2010*1000/total10)

plot(ua2010state, uachange9010, pch=21, xlab=" ", ylab=" ", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,2300), xlim=c(0,7), col="black", bg="black")

detach(nd)
remove(list=ls())



rs<-read.dta("pop9010REMAINING.dta") #Stata file with demographic data#
attach(rs)


#Creates Plots of Population Characteristics: Figure 1

par(new="TRUE")

uachange9010<-100*((unauth2010-unauth90)/unauth90)
ua2010state<-100*(unauth2010*1000/total10)

plot(ua2010state, uachange9010, pch=1, xlab=" ", ylab=" ", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,2300), xlim=c(0,7), col="black", bg="white")

detach(rs)
remove(list=ls())


###########################
HISPANIC CHANGE BY UA
############################


trad<-read.dta("pop9010TRAD.dta") #Stata file with demographic data#
attach(trad)


#Plot 1: 
#x=Hispanic State Population Consisting 
#y-Percentage Change in Hisp Pop, 1990 to 2010 

uachange9010<-100*((unauth2010-unauth90)/unauth90)

 
plot(uachange9010, roc_hispanic, pch=21, xlab="Percent Change Unauthorized, 1990-2010", ylab="% Change Hispanic, 1990-2010", main="E. Hisp. Pop. by Unauth. Pop.", cex.main=.85,
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,2500), col="gray", bg="gray")
legend("topleft", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), bg=c("black", "gray", "gray"), col=c("black", "gray", "grey"),   bty="n", cex=.65)
text(2000, 200, "r=.72 (.00)", col="black", cex=.65)



detach(trad)
remove(list=ls())


nd<-read.dta("pop9010NEWDEST.dta") #Stata file with demographic data#
attach(nd)

par(new="TRUE")


uachange9010<-100*((unauth2010-unauth90)/unauth90)

 
plot(uachange9010, roc_hispanic, pch=21,  cex.main=.85, xlab="", ylab="",
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,2500), col="black", bg="black")

detach(nd)
remove(list=ls())


rs<-read.dta("pop9010REMAINING.dta") #Stata file with demographic data#
attach(rs)


#Creates Plots of Population Characteristics: Figure 1

par(new="TRUE")


uachange9010<-100*((unauth2010-unauth90)/unauth90)



plot(uachange9010, roc_hispanic, pch=1, cex.main=.85, xlab="", ylab="",
cex.lab=.85, cex.axis=.85, ylim=c(0,1000), xlim=c(0,2500), col="black", bg="white")



detach(rs)
remove(list=ls())

#######################################
####CONGRESSIONAL DISTRICT PLOTS#######
#######################################


setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
trad<-read.dta("districtTRAD.dta") #Stata file with demographic data#
attach(trad)


hs9010<-hs9010*100
hd0010<-hd0010*100
disthispanicpct_10<-disthispanicpct_10*100


plot(disthispanicpct_10, hd0010, pch=21, xlab="Percent Hispanic (District), 2010", ylab="% Change (District), 2000-2010", main="F. District Hispanic Population", cex.main=.85, cex=.55,
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,100),col="gray", bg="gray")
legend("topright", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), col=c("black", "gray", "black"), bg=c("black", "gray", "black"), bty="n", cex=.65)
text(70, 40, "r=-.73 (.00)", col="black", cex=.65)


detach(trad)
remove(list=ls())

par(new="TRUE")


setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
nd<-read.dta("districtND.dta") #Stata file with demographic data#
attach(nd)


hs9010<-hs9010*100
hd0010<-hd0010*100
disthispanicpct_10<-disthispanicpct_10*100


plot(disthispanicpct_10, hd0010, pch=21, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,100),col="black", bg="black")

detach(nd)
remove(list=ls())

par(new="TRUE")


setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
other<-read.dta("districtOTHER.dta") #Stata file with demographic data#
attach(other)

hs9010<-hs9010*100
hd0010<-hd0010*100
disthispanicpct_10<-disthispanicpct_10*100



plot(disthispanicpct_10, hd0010, pch=1, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,100))


detach(other)
remove(list=ls())


#####By State Change: HISPANIC#####

setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
trad<-read.dta("districtTRAD.dta") #Stata file with demographic data#
attach(trad)

hs9010<-hs9010*100
hd0010<-hd0010*100

plot(hs9010, hd0010, pch=21, xlab="Percent Change (State), 2010", ylab="% Change (District), 2000-2010", main="G. Dist. Hisp. by State Hisp. Population", cex.main=.85, cex=.35, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,1000),col="gray", bg="gray")
legend("topright", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), col=c("black", "gray", "black"),   bty="n", cex=.65)
text(800, 10, "r=.44 (.00)", col="black", cex=.65)


detach(trad)

remove(list=ls())



par(new="TRUE")



setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
newdest<-read.dta("districtND.dta") #Stata file with demographic data#
attach(newdest)


hs9010<-hs9010*100
hd0010<-hd0010*100

plot(hs9010, hd0010, pch=21, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,1000), bg="black")
detach(newdest)
remove(list=ls())




par(new="TRUE")



setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
other<-read.dta("districtOTHER.dta") #Stata file with demographic data#
attach(other)


hs9010<-hs9010*100
hd0010<-hd0010*100

plot(hs9010, hd0010, pch=1, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,1000), col="black", bg="white")

detach(other)
remove(list=ls())




#####By State Change: FOR BORN#####

setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
trad<-read.dta("districtTRAD.dta") #Stata file with demographic data#
attach(trad)

hs9010<-hs9010*100
hd0010<-hd0010*100

plot(fs9010, hd0010, pch=21, xlab="Percent Change For. Born (State)", ylab="% Change Hisp. (District), 2000-2010", main="H. Dist. Hisp. by State For. Born", cex.main=.85, cex=.35, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,600),col="gray", bg="gray")
legend("topright", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), col=c("black", "gray", "black"),   bty="n", cex=.65)
text(400, 10, "r=.26 (.00)", col="black", cex=.65)


detach(trad)

remove(list=ls())



par(new="TRUE")



setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
newdest<-read.dta("districtND.dta") #Stata file with demographic data#
attach(newdest)


hs9010<-hs9010*100
hd0010<-hd0010*100

plot(fs9010, hd0010, pch=21, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,600), bg="black")
detach(newdest)
remove(list=ls())




par(new="TRUE")



setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
other<-read.dta("districtOTHER.dta") #Stata file with demographic data#
attach(other)


hs9010<-hs9010*100
hd0010<-hd0010*100

plot(fs9010, hd0010, pch=1, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,600), col="black", bg="white")

detach(other)
remove(list=ls())




#####By State Change: UNAUTH#####

setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
trad<-read.dta("districtTRAD.dta") #Stata file with demographic data#
attach(trad)

hs9010<-hs9010*100
hd0010<-hd0010*100

plot(uachange9010, hd0010, pch=21, xlab="Percent Change Unauth. (State)", ylab="% Change Hisp. (District), 2000-2010", main="I. Dist. Hisp. by State Unauth.", cex.main=.85, cex=.35, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,1800),col="gray", bg="gray")
legend("topright", c("New Dest.", "Trad.", "Other"), pch=c(19, 19, 1), col=c("black", "gray", "black"),   bty="n", cex=.65)
text(1250, 10, "r=.51 (.00)", col="black", cex=.65)


detach(trad) 

remove(list=ls())



par(new="TRUE")



setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
newdest<-read.dta("districtND.dta") #Stata file with demographic data#
attach(newdest)


hs9010<-hs9010*100
hd0010<-hd0010*100

plot(uachange9010, hd0010, pch=21, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,1800), bg="black")
detach(newdest)
remove(list=ls())




par(new="TRUE")



setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")
other<-read.dta("districtOTHER.dta") #Stata file with demographic data#
attach(other)


hs9010<-hs9010*100
hd0010<-hd0010*100

plot(uachange9010, hd0010, pch=1, xlab="", ylab="", main="", cex.main=.85, cex=.55, 
cex.lab=.85, cex.axis=.85, ylim=c(-10,80), xlim=c(0,1800), col="black", bg="white")

detach(other)
remove(list=ls())







title("Population Characteristics for Hispanic, Foreign Born, and Unauthorized Populations", outer="TRUE")

dev.off()